package com.smartstate.EMS.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smartstate.common.util.excelPro.ExcelExportDto;
import com.smartstate.EMS.dto.ToolDTO;
import com.smartstate.EMS.dto.PageDTO;
import com.smartstate.EMS.dto.update.ToolUpdateDTO;
import com.smartstate.EMS.entity.Tool;
import com.smartstate.EMS.service.ToolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = {"刀具控制器"})
@RequestMapping("/Tool")
public class ToolController {
  @Resource
  private ToolService service;

  @GetMapping ("/getAll")
  @ApiOperation(value = "查询所有刀具模型")
  public List<Tool> getAll() {
    return service.list();
  }

  @PostMapping ("/saveOrUpdate")
  @ApiOperation(value = "新增或修改刀具模型")
  public boolean saveOrUpdate(@RequestBody Tool item) {
    return service.saveOrUpdate(item);
  }

  @DeleteMapping ("/removeByIds")
  @ApiOperation(value = "根据ID批量删除刀具模型")
  public boolean removeByIds(@RequestBody List<Integer> item) {
    return service.removeByIds(item);
  }

  @DeleteMapping("/removeById")
  @ApiOperation(value = "根据ID删除刀具模型")
  public boolean removeById(@RequestBody Integer item) {
    return service.removeById(item);
  }

  @PostMapping ("/queryPage")
  @ApiOperation(value = "单表分页查询刀具模型")
  public Page<Tool> getPage(@RequestBody PageDTO<ToolDTO> pageDTO) {
    //分页查询无页数与条数，默认为第1页10条数据。
    return service.queryAllPageByDTO(pageDTO);
  }

  @PutMapping ("/updateByDto")
  @ApiOperation(value = "根据刀具DTO修改刀具")
  public int updateByDTO(@RequestBody ToolUpdateDTO dto) {
    return service.updateByDTO(dto);
  }

  /**
   * 导入数据
   */
  @PostMapping ("/importData")
  @ApiOperation(value = "导入数据")
  public int importData(@RequestPart MultipartFile file) {
    return service.importData(file);
  };
  /**
   * 导出模板
   * @return
   */
  @PostMapping ("/exportTemplate")
  @ApiOperation(value = "导出模板")
  public ExcelExportDto exportTemplate(){
    return service.exportTemplate();
  };

  /**
   * 导出单表数据
   * @return
   */
  @PostMapping ("/exportData")
  @ApiOperation(value = "导出单表数据")
  public ExcelExportDto exportData(ToolDTO dto){
    return service.exportData(dto);
  };
}
